//
//  AddViewController.m
//  08-Homework
//
//  Created by dllo on 16/7/25.
//  Copyright © 2016年 LST. All rights reserved.
//

#import "AddViewController.h"
#import "Model.h"

@interface AddViewController ()
@property (nonatomic, retain) UITextField *text;
@property (nonatomic, retain) UITextField *text2;
@property (nonatomic, retain) UITextField *text3;
@property (nonatomic, retain) UITextField *text4;
@property (nonatomic, retain) UIButton *btn;
@end

@implementation AddViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    [self creatTextField];
}
- (void)creatTextField {
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(80, 150, 80, 50)];
    label.text = @"姓名:";
    [self.view addSubview:label];
    self.text = [[UITextField alloc] initWithFrame:CGRectMake(140, 150, 200, 50)];
    self.text.layer.borderWidth = 1;
    self.text.clearButtonMode = UITextFieldViewModeWhileEditing;
    [self.view addSubview:self.text];
    UILabel *label2 = [[UILabel alloc] initWithFrame:CGRectMake(80, 330, 80, 50)];
    label2.text = @"电话:";
    [self.view addSubview:label2];
    self.text2 = [[UITextField alloc] initWithFrame:CGRectMake(140, 330, 200, 50)];
    self.text2.layer.borderWidth = 1;
    [self.view addSubview:self.text2];
    
    UILabel *label3 = [[UILabel alloc] initWithFrame:CGRectMake(80, 210, 80, 50)];
    label3.text = @"年龄:";
    [self.view addSubview:label3];
    self.text3= [[UITextField alloc] initWithFrame:CGRectMake(140, 210, 200, 50)];
    self.text3.layer.borderWidth = 1;
    [self.view addSubview:self.text3];
    UILabel *label4 = [[UILabel alloc] initWithFrame:CGRectMake(80, 270, 80, 50)];
    label4.text = @"性别:";
    [self.view addSubview:label4];
    self.text4 = [[UITextField alloc] initWithFrame:CGRectMake(140, 270, 200, 50)];
    self.text4.layer.borderWidth = 1;
    [self.view addSubview:self.text4];
    self.btn = [UIButton buttonWithType:UIButtonTypeCustom];
    self.btn.frame = CGRectMake(150, 500, 100, 50);
    self.btn.layer.borderWidth = 2.0;
    [self.btn setTitle:@"保存" forState:UIControlStateNormal];
    [self.btn addTarget:self action:@selector(addBtn:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.btn];
}
- (void)addBtn:(UIButton *)sender {
    self.modelStu = [[Model alloc] init];
    self.modelStu.name = _text.text;
    _modelStu.gender = _text4.text;
    _modelStu.age = [NSNumber numberWithFloat:[_text3.text floatValue]];
    _modelStu.phoneNumber = _text2.text;
    if (self.delegate && [self.delegate respondsToSelector:@selector(addModel:)]) {
        [self.delegate addModel:_modelStu];
    }
    [self.navigationController popToRootViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
